home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / src / MGL / halftone.h < prev    next >
C/C++ Source or Header  |  1999-02-04  |  7KB  |  187 lines

  1. /****************************************************************************
  2. *
  3. *                      Mesa bindings for SciTech MGL
  4. *
  5. *               Copyright (C) 1996-1998 SciTech Software, Inc.
  6. *                            All rights reserved.
  7. *
  8. * Language:        ANSI C
  9. * Environment:    IBM PC (MS DOS)
  10. *
  11. * Description:    Header file for the windows compatible HalfToning tables
  12. *                for creating a HalfTone palette and for performing the
  13. *                HalfTone dithering algorithm in 8/15/16 bpp modes.
  14. *
  15. *                The halftone palette is set up to use entries from 20 to
  16. *                226 in the physical palette, leaving the top 20 and bottom
  17. *                20 for operating system specific use.
  18. *
  19. * This library is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU Library General Public
  21. * License as published by the Free Software Foundation; either
  22. * version 2 of the License, or (at your option) any later version.
  23. *
  24. * This library is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  27. * Library General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU Library General Public
  30. * License along with this library; if not, write to the Free
  31. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  32. *
  33. ****************************************************************************/
  34.  
  35. #ifndef    __HALFTONE_H
  36. #define    __HALFTONE_H
  37.  
  38. /*---------------------- Macro and type definitions -----------------------*/
  39.  
  40. /* Macros to halfTone dither an 8bpp RGB pixel */
  41.  
  42. #define    PACK_COLOR_DITHER8(p,x,y,R,G,B)                            \
  43. {                                                                \
  44.     uchar dither = _MGL_dither8x8[(((y) & 7) << 3) + ((x) & 7)];\
  45.     (p) = 20 +                                                     \
  46.         _MGL_div51[R] + (_MGL_mod51[R] > dither) +                \
  47.         _MGL_mul6[_MGL_div51[G] + (_MGL_mod51[G] > dither)] +    \
  48.         _MGL_mul36[_MGL_div51[B] + (_MGL_mod51[B] > dither)];    \
  49. }
  50.  
  51. #define    HALFTONE_VARS_8                                            \
  52.     int    __Rdiv51,__Rmod51;                                    \
  53.     int    __Gdiv51,__Gmod51;                                    \
  54.     int    __Bdiv51,__Bmod51;                                    \
  55.     uchar  *__dp
  56.  
  57. #define    SETUP_DITHER8(y,R,G,B)                                    \
  58. {                                                                \
  59.     __dp = &_MGL_dither8x8[((y) & 7) << 3];                        \
  60.     __Rdiv51 = _MGL_div51[R];                                    \
  61.     __Rmod51 = _MGL_mod51[R];                                    \
  62.     __Gdiv51 = _MGL_div51[G];                                    \
  63.     __Gmod51 = _MGL_mod51[G];                                    \
  64.     __Bdiv51 = _MGL_div51[B];                                    \
  65.     __Bmod51 = _MGL_mod51[B];                                    \
  66. }
  67.  
  68. #define    PACK_COLOR2_DITHER8(p,x)                                \
  69. {                                                                \
  70.     uchar __dither = __dp[(x) & 7];                                \
  71.     (p) = 20 +                                                    \
  72.         __Rdiv51 + (__Rmod51 > __dither) +                        \
  73.         _MGL_mul6[__Gdiv51 + (__Gmod51 > __dither)] +            \
  74.         _MGL_mul36[__Bdiv51 + (__Bmod51 > __dither)];            \
  75. }
  76.  
  77. /* Macros to halfTone dither a 16bit 5/5/5 RGB pixel */
  78.  
  79. #define    PACK_COLOR_DITHER555(p,x,y,R,G,B)                                \
  80. {                                                                        \
  81.     uchar _dither = _MGL_dither4x4[(((y) & 3) << 2) + ((x) & 3)];         \
  82.     (p) = (ushort)                                                       \
  83.        ((((ulong)_MGL_div8[R] + (_MGL_mod8[R] > _dither)) << 10) +      \
  84.         (((ulong)_MGL_div8[G] + (_MGL_mod8[G] > _dither)) << 5) +       \
  85.         (((ulong)_MGL_div8[B] + (_MGL_mod8[B] > _dither)) << 0));       \
  86. }
  87.  
  88. #define    HALFTONE_VARS_16                                        \
  89.     int    __Rdiv8,__Rmod8;                                        \
  90.     int    __Gdiv8,__Gmod8;                                        \
  91.     int    __Bdiv8,__Bmod8;                                        \
  92.     uchar  *__dp
  93.  
  94. #define    SETUP_DITHER555(y,R,G,B)                                \
  95. {                                                                \
  96.     __dp = &_MGL_dither4x4[((y) & 3) << 2];                        \
  97.     __Rdiv8 = _MGL_div8[R];                                        \
  98.     __Rmod8 = _MGL_mod8[R];                                        \
  99.     __Gdiv8 = _MGL_div8[G];                                        \
  100.     __Gmod8 = _MGL_mod8[G];                                        \
  101.     __Bdiv8 = _MGL_div8[B];                                        \
  102.     __Bmod8 = _MGL_mod8[B];                                        \
  103. }
  104.  
  105. #define    PACK_COLOR2_DITHER555(p,x)                                \
  106. {                                                                \
  107.     uchar _dither = __dp[(x) & 3];                                \
  108.     (p) = (ushort)                                              \
  109.        (((__Rdiv8 + (__Rmod8 > _dither)) << 10) +                  \
  110.         ((__Gdiv8 + (__Gmod8 > _dither)) << 5) +                   \
  111.         ((__Bdiv8 + (__Bmod8 > _dither)) << 0));                   \
  112. }
  113.  
  114. /* Macros to halfTone dither a 16bit 5/6/5 RGB pixel */
  115.  
  116. #define    PACK_COLOR_DITHER565(p,x,y,R,G,B)                                \
  117. {                                                                        \
  118.     uchar _dither = _MGL_dither4x4[(((y) & 3) << 2) + ((x) & 3)];         \
  119.     (p) = (ushort)                                                       \
  120.        ((((ulong)_MGL_div8[R] + (_MGL_mod8[R] > _dither)) << 11) +      \
  121.         (((ulong)_MGL_div4[G] + (_MGL_mod4[G] > (_dither>>1))) << 5) +  \
  122.         (((ulong)_MGL_div8[B] + (_MGL_mod8[B] > _dither)) << 0));       \
  123. }
  124.  
  125. #define    SETUP_DITHER565(y,R,G,B)                                \
  126. {                                                                \
  127.     __dp = &_MGL_dither4x4[((y) & 3) << 2];                        \
  128.     __Rdiv8 = _MGL_div8[R];                                        \
  129.     __Rmod8 = _MGL_mod8[R];                                        \
  130.     __Gdiv8 = _MGL_div4[G];                                        \
  131.     __Gmod8 = _MGL_mod4[G];                                        \
  132.     __Bdiv8 = _MGL_div8[B];                                        \
  133.     __Bmod8 = _MGL_mod8[B];                                        \
  134. }
  135.  
  136. #define    PACK_COLOR2_DITHER565(p,x)                                \
  137. {                                                                \
  138.     uchar __dither = __dp[(x) & 3];                             \
  139.     (p) = (ushort)                                                \
  140.        (((__Rdiv8 + (__Rmod8 > __dither)) << 11) +                \
  141.         ((__Gdiv8 + (__Gmod8 > (__dither>>1))) << 5) +            \
  142.         ((__Bdiv8 + (__Bmod8 > __dither)) << 0));                \
  143. }
  144.  
  145. /*--------------------------- Global Variables ----------------------------*/
  146.  
  147. extern palette_t    _VARAPI _MGL_halftonePal[];
  148.  
  149. /* Division lookup tables.  These tables compute 0-255 divided by 51 and
  150.  * modulo 51.  These tables could approximate gamma correction.
  151.  */
  152.  
  153. extern unsigned char _VARAPI _MGL_div51[256];
  154. extern unsigned char _VARAPI _MGL_mod51[256];
  155. extern unsigned char _VARAPI _MGL_div8[256];
  156. extern unsigned char _VARAPI _MGL_mod8[256];
  157. extern unsigned char _VARAPI _MGL_div4[256];
  158. extern unsigned char _VARAPI _MGL_mod4[256];
  159.  
  160. /* Multiplication lookup tables. These compute 0-5 times 6 and 36. */
  161.  
  162. extern unsigned char _VARAPI _MGL_mul6[6];
  163. extern unsigned char _VARAPI _MGL_mul36[6];
  164.  
  165. /* Dither matrices */
  166.  
  167. extern unsigned char _VARAPI _MGL_dither8x8[64];
  168. extern unsigned char _VARAPI _MGL_dither4x4[16];
  169.  
  170. /*------------------------- Function Prototypes ---------------------------*/
  171.  
  172. #ifdef    __cplusplus
  173. extern "C" {
  174. #endif
  175.  
  176. void     MGLAPI MGL_getHalfTonePalette(palette_t *pal);
  177. uchar     MGLAPI MGL_halfTonePixel(int x,int y,uchar R,uchar G,uchar B);
  178. ushort     MGLAPI MGL_halfTonePixel555(int x,int y,uchar R,uchar G,uchar B);
  179. ushort     MGLAPI MGL_halfTonePixel565(int x,int y,uchar R,uchar G,uchar B);
  180.  
  181. #ifdef    __cplusplus
  182. }
  183. #endif
  184.  
  185. #endif    /* __HALFTONE_H */
  186.  
  187.